package tung.niit.ict;

import java.util.ArrayList;

import tung.niit.ict.adapter.LendedBookAdapter;
import tung.niit.ict.model.LendedBook;
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.AdapterView.OnItemClickListener;

public class Information extends Activity {

	private TabHost tab;
	private ListView listLendedBook;
	private ArrayList<LendedBook> arrayLendedBook;
	private LendedBookAdapter adapter;
	
	private String[] idlendingBook;
	private ArrayAdapter<String> adapterIdLendingBook;
	private AutoCompleteTextView idBook;
	
	private String[] namelendingBook;
	private ArrayAdapter<String> adapterNameLendingBook;
	private AutoCompleteTextView nameBook;
	
	private String[] authorLendingBook;
	private ArrayAdapter<String> adapterAuthorLendingBook;
	private AutoCompleteTextView authorBook;
	
	private String[] yearLendingBook;
	private ArrayAdapter<String> adapterYear;
	private Spinner yearBook;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.infomation);
		
		tab = (TabHost)findViewById(android.R.id.tabhost);
		tab.setup();
		TabHost.TabSpec spec;
		
		spec = tab.newTabSpec("t1");
		spec.setContent(R.id.tabprofile);
		spec.setIndicator("Profile");
		tab.addTab(spec);
		
		spec = tab.newTabSpec("t2");
		spec.setContent(R.id.tablendingbook);
		spec.setIndicator("Leding Book");
		tab.addTab(spec);
		
		tab.setCurrentTab(0);
		
		listLendedBook = (ListView)findViewById(R.id.listviewLendedBook);
		arrayLendedBook = new ArrayList<LendedBook>();
		createLendedBook();
		adapter = new LendedBookAdapter(Information.this, R.layout.item_lendedbook, arrayLendedBook);
		listLendedBook.setAdapter(adapter);
		
		idBook = (AutoCompleteTextView)findViewById(R.id.autotextIDLendingBook);
		idlendingBook = getResources().getStringArray(R.array.idlendingbook);
		adapterIdLendingBook = new ArrayAdapter<String>(this, R.layout.item_lending_book, idlendingBook);
		idBook.setAdapter(adapterIdLendingBook);
		
		nameBook = (AutoCompleteTextView)findViewById(R.id.autotextNameLendingBook);
		namelendingBook = getResources().getStringArray(R.array.namlendingbook);
		adapterNameLendingBook = new ArrayAdapter<String>(this, R.layout.item_lending_book, namelendingBook);
		nameBook.setAdapter(adapterNameLendingBook);
		
		authorBook = (AutoCompleteTextView)findViewById(R.id.autotextAuthorLendingBook);
		authorLendingBook = getResources().getStringArray(R.array.authorlendingbook);
		adapterAuthorLendingBook = new ArrayAdapter<String>(this, R.layout.item_lending_book, authorLendingBook);
		authorBook.setAdapter(adapterAuthorLendingBook);
		
		yearBook = (Spinner)findViewById(R.id.spinnerLendingBook);
		yearLendingBook = getResources().getStringArray(R.array.yearlendingbook);
		adapterYear = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, yearLendingBook);
		adapterYear.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
		yearBook.setAdapter(adapterYear);
		
	}
	
	private void createLendedBook() {
		LendedBook book1 = new LendedBook(
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), 
				"Dieu Che tin hieu so", 
				"IT123", 
				"Trinh Van Loan", 
				"2004", 
				"20000", 
				"http://google.com.vn");
		arrayLendedBook.add(book1);
	}
}
